<div class="restpwd">
    <form class="niceform" id="myform" action="" method="post">
        <?php if($result === 'success'): ?>
        <div  class="restpwd-title">设置您的新密码</div>
        <div class="restpwd-con">
            <p>您正在设置<span><?php if($result == 'success'){echo $email;} ?></span> 的新密码</p>
            <div class="input-group">
                <label for="newpwd" class="input-group-addon">新密码</label>
                <input type="password" name="newpwd" id="newpwd" class="form-control" maxlength="30" required="required" placeholder="请填写你的密码"/>
                <input type="hidden" name="email" id="email" value="<?php if($result == 'success'){echo $email;} ?>" />
                <input type="hidden" name="key" id="key" value="<?php if($result == 'success'){echo $key;} ?>" />
            </div>
            <input type="submit" class="btn btn-success form-control" id="resetBtn" value="确定修改密码">
            <span id="response"></span>
            <?php else: ?>
                <div class="restpwd-con setnewpw-warn">
                    链接已失效!请<a href="<?php echo base_url('home/resetpwd') ?>">重新获取重置密码邮件</a>
                </div>
            <?php endif; ?>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        $('#myform').validate({
            submitHandler: function (form) {
                $.ajax({
                    url:"<?php echo base_url('api/setnewpwd') ?>",
                    type:"post",
                    data:$('#myform').serialize(),
                    dataType:"json",
                    beforeSend:function(){
                        showProgressNoty();
                    },
                    complete: function () {
                        closeProgressNoty();
                    },
                    success:function(rsp){
                        try {
                            noty({type: rsp.type, text: rsp.message, callback: {
                                afterClose: function () {
                                    switch (rsp.type) {
                                        case 'success':
                                            window.location.href='<?php echo base_url('') ?>';
                                            break;
                                        case 'error':
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }});
                        } catch (ex) {
                            noty({type: 'error', text: '发生内部错误，请联系管理员'});
                            throw ex;
                        }
                    }
                });
            }
        });
    });
</script>